package com.ijunfu.detail.thread._01_Thread;

import lombok.extern.slf4j.Slf4j;

import java.util.stream.IntStream;

/**
 *
 * @Title  : 
 * @Author : ijunfu <ijunfu@163.com>
 * @Date   : 2023/11/23 16:39
 * @Version: 1.0
 * @Motto  : 世界很大 世界很小
 *
 */
@Slf4j
public class _09Main {

    public static void main(String[] args) {

        Thread t1 = new Thread(()->{
            log.info("开始执行...");
            // 判断线程是否被打断
            boolean isInterrupted = Thread.currentThread().isInterrupted();     // true
            log.info("1. isInterrupted={}", isInterrupted);

            // 清除打断标记，让线程继续执行
            Thread.interrupted();

            // 判断线程是否被打断
            isInterrupted = Thread.currentThread().isInterrupted();             // false
            log.info("2. isInterrupted={}", isInterrupted);

            IntStream.range(0,5).forEach(idx->{
                log.info("{}", idx);
            });
        });

        // 启动线程
        t1.start();

        // 中断线程
        t1.interrupt();
    }
}
